This document describes how to use the XMLDoc demo project to generate documentation from XML comments in Delphi and C# code. For Delphi code, the XMLDoc tool reads the xml file generated by the Delphi compiler's --doc switch. For C#, the tool combines the output from the C# compiler's /doc switch with metadata from reflection. Source code comments that use a special syntax are inserted into HTML files identical to those used for the Developer Studio 2006 product API documentation. These files can be viewed with any HTML browser. Links are in the Microsoft Help 2.0 format, so they will not function as-is. For full functionality, the files can be compiled into the Microsoft Help 2.0 compiled help format using the Borland HelpKit and the Visual Studio Help Integration Kit.
Requirements
The XMLDoc tool requires a number of supporting tools:
Setup
To prepare to use the XMLDoc tool, add the directory containing the tool to your path. In the default installation, this path is C:\Program Files\Borland\BDS\4.0\Demos\XMLDoc. Consult your operating system documentation for instructions on changing your path environment variable.
You should also add the directory containing Python to your path if it is not already there. Because the XMLDoc tool executes saxon from the command line, if you use the full version of Saxon you will need to use a batch file to start Saxon. The batch file should be called saxon.bat, and should look something like this (change the path to match your local Saxon installation):
@java -jar "C:\Program Files\Saxon 6.5.3\saxon.jar" %1 %2 %3
Place this batch file in your path.
Basic usage
There are three major tasks you need to perform to produce XML documentation from source code comments:
Each of these steps is broken into subtasks below.
Using the Delphi or C# compiler to generate the XML file with source code comments
For your comments to appear in the output, you must use one of the special XML documentation comment marker styles:
/// This comment goes until the end of the line -- works in Delphi and C#
{! This is also a comment -- works only in Delphi }
{*! and this too -- works only in Delphi *}
The relevant documentation should appear directly above the declaration of the documented type or member. For example:
[Delphi] /// The TFooBar class includes an extremely useful method. type TFooBar = class(System.Windows.Forms.Form); public /// The method FooMethod is extremely useful. function FooMethod: Integer; end;
[C#]
/// The FooBar class includes an extremely useful method.
class FooBar : System.Windows.Forms.Form
{
/// The method FooMethod is extremely useful.
public int FooMethod();
}
Note: Private members may not be processed by the XMLDoc tool.
Using the XMLDoc tool to produce HTML files in the format used by Microsoft Help 2.0
xmldoc.py <MyProjectDir>, where <MyProjectDir> is the project directory for the project you are documenting. By default this will be something like xmldoc.py "C:\Documents and Settings\UserName\My Documents\Borland Studio Projects\Project1". Don't forget the quotes if your project directory name has spaces in it.
doc subdirectory of your project directory, and examine the output HTML files in doc/final.
Using the Visual Studio Help Integration Kit and the Borland HelpKit to compile and install the new help topics
Advanced usage
The XMLDoc tool is very flexible. You can use source files outside of your code if desired. Also, by customizing stylesheets, you can produce documentation with whatever appearance or structure you desire.
Maintaining content outside of code
It can be desirable to divide the tasks of development and documentation. The XMLDoc tool automatically produces template files that can be altered by a technical writer, independently of the source code. These files are written to the doc/templates directory under your project. Content files, which include the comments from source code, are written to the doc/content directory. To develop content independent of source code comments:<MyContentDir>.xmldoc.py <MyProjectDir> <MyContentDir> (replacing the directories with the names of your project and content file directories) to use these content files rather than the source code comments directly.Customizing look-and-feel
Modify the cascading stylesheet, bdshelp.css, to give the documentation a custom look-and-feel.Customizing structure
Modify the XSLT stylesheets to make more extensive changes to the output format. The XSLT stylesheets, .xsl files, can be customized to make significant structural changes. The most important stylesheet for customization is the h2build.xsl file, located in the APIMerge subdirectory of the XMLDoc demo project. For example, this file can be modified to produce ordinary HTML links instead of Microsoft Help links, if desired (see htmlbuild.xsl). Many other customizations are possible.